/**
  ******************************************************************************
  * @file           
  * @author         东方电科
  * @brief          在此处编写应用层的 ASDU 处理
  *                 依赖 IEC_ASDU.c
  ******************************************************************************
  *
  * COPYRIGHT(c) 2019 GoodMorning
  *
  ******************************************************************************
  */
/* Includes ---------------------------------------------------*/
#include <string.h>
#include "iec10x.h"
#include "iec10x_debug.h"


#if (ENABLE_FILE_TRANS)

#include "iec_file.h"

/**
  * @brief    iec10x 文件传输服务响应
  * @return   成功返回 0
*/
void iec10x_file_service(iec10x_t * bus , uint8_t * ASDU, int ASDUlen)
{
	if (bus->mode & IEC_101) {
		iec10x_warn(bus,"fs do not support for iec101.\r\n");
		return;
	}
	else
	if (!(bus->mode & IEC_MASTER)) {
		extern void iec104slv_file_service(iec10x_t * bus , uint8_t * ASDU,int len);
		iec104slv_file_service(bus,ASDU,ASDUlen);
	}
	else {
		extern void iec104mst_file_service(iec10x_t * bus , uint8_t * ASDU,int len);
		iec104mst_file_service(bus,ASDU,ASDUlen);
	}
}


/**
  * @brief    切换 iec104 当前工作目录
  * @param    bus    : 总线
  * @param    dir    : 路径
  * @return   成功返回 0
*/
int iec10x_change_dir(iec10x_t * bus , const char * dir)
{
	int len = strlen(dir);
	if (len >= sizeof(bus->workdir)) {
		return -1;
	}

	memcpy(bus->workdir, dir,len);
	bus->workdir[len] = '\0';
	return 0;
}

#endif /* ENABLE_FILE_TRANS */

